package com.deep.deepenterpise.common.util;

import com.deep.deepenterpise.common.DrGson;
import com.deep.deepenterpise.common.result.DrRequest;

/**
 * @author xyz
 * @version 1.0
 * @title DrRequestUtil
 * @description TODO 请求结果处理工具类
 * @create 2024/4/16 14:19
 */
public class DrRequestUtil {
    private DrRequestUtil() {
    }

    /**
     * @return boolean
     * @Auth xyz
     * @Desc //TODO 解析请求结果，判断请求是否成功
     * @Time 08:52 2024/4/18
     * @Param [json]
     */
    public static boolean isSuccess(String json) {
        if (!DrGson.validate(json)) {
            return false;
        }
        DrRequest drRequest = toDrRequest(json);
        if (drRequest == null) {
            return false;
        }
        return isSuccess(drRequest);
    }

    public static boolean isSuccess(DrRequest drRequest) {
        return drRequest.getDrCode() == 200;
    }

    /**
     * @return com.deep.deepbottlecurrent.DrEntity.DrCommon.DrRequest
     * @Auth xyz
     * @Desc //TODO 将json字符串转换为DrRequest对象
     * @Time 08:53 2024/4/18
     * @Param [json]
     */
    public static DrRequest toDrRequest(String json) {
        try {
            return DrGson.parseObject(json, DrRequest.class);
        } catch (Exception e) {
            return null;
        }
    }
}
